{% extends 'home_page/base_index.html' %}
{% load static %}


{% block show_body %}
    <section id="multiple-column-form">
        <div class="row match-height">
            <div class="col-12">
                <div class="card">
                    <div class="card-header"><h4 class="card-title">发布就业岗位</h4></div>
                    <div class="card-content">
                        <div class="card-body">
                            <form id="postJobForm" class="form">
                                {% csrf_token %}
                                <div class="row">
                                    <div class="col-md-6 col-12">
                                        <div class="form-group">
                                            <label for="first-name-column">岗位名称</label>
                                            <input name="title"
                                                   type="text" id="first-name-column" class="form-control"
                                                   placeholder="Job title"></div>
                                    </div>
                                    <div class="col-md-6 col-12">
                                        <div class="form-group"><label for="last-name-column">岗位描述</label><input
                                                type="text" id="last-name-column" class="form-control"
                                                placeholder="Job description" name="description"></div>
                                    </div>
                                    <div class="col-md-6 col-12">
                                        <div class="form-group">
                                            <label for="city-column">任职要求</label>
                                            <input type="text"
                                                   id="city-column"
                                                   class="form-control"
                                                   placeholder="Job requirements"
                                                   name="requirements">
                                        </div>
                                    </div>
                                    <div class="col-md-6 col-12">
                                        <div class="form-group"><label for="country-floating">薪资范围</label><input
                                                type="text" id="country-floating" class="form-control"
                                                name="salary_range" placeholder="Salary range"></div>
                                    </div>
                                    <div class="col-md-6 col-12">
                                        <div class="form-group"><label for="company-column">工作地点</label><input
                                                type="text" id="company-column" class="form-control"
                                                name="location"
                                                placeholder="Work place"></div>
                                    </div>
                                    <div class="col-md-6 col-12">
                                        <div class="form-group"><label for="email-id-column">截止日期</label><input
                                                type="date" id="email-id-column" class="form-control"
                                                name="deadline" placeholder="Deadline date"></div>
                                    </div>
                                    <div class="form-group col-12">
                                        <div class="form-check">

                                        </div>
                                    </div>
                                    <div class="col-12 d-flex justify-content-end">
                                        <button type="button" class="btn btn-primary me-1 mb-1" onclick="submitJobForm()">发布</button>
                                        <button type="reset" class="btn btn-light-secondary me-1 mb-1">重置</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
{% endblock %}


{% block show_user %}
    {# 当企业登录的时候显示组织的名称和账号 #}
    <div class="card">
        <div class="card-body py-4 px-5">
            <div class="d-flex align-items-center">
                <div class="avatar avatar-xl">
                    <img src="{% static 'picture/5.jpg' %}" alt="Face female">
                </div>
                {# 加载企业的姓名和学号 #}
                <div class="ms-3 name"><h5 class="font-bold">名称：{{ organization.name }}</h5>
                    <h6 class="text-muted mb-0">
                        账号：{{ request.session.user_id }}
                    </h6>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block script_block %}
    <script>
        function submitJobForm() {
            $.ajax({
                url: '{% url 'organization:post_jobs' %}',
                type: 'POST',
                data: $('#postJobForm').serialize(),
                headers: {"X-CSRFToken": $("[name='csrfmiddlewaretoken']").val()},
                success: function (data) {
                    if (data.code === 200) {
                        alert('发布成功！');
                        // 刷新页面
                        window.location.reload();
                    } else {
                        alert('发布失败！');
                    }
                },
                error: function (error) {
                    console.error('请求数据失败:', error);
                }
            });
        }
    </script>
{% endblock %}

